<?php

	define( 'ROOT_PATH', dirname( __FILE__ ) );

	session_start();
	//include	'../init.php';
	header( "Content-type: image/PNG" );
	//	[CH]	生成随机数字的种子，以方便下面随机数生成的使用
	/*
	+----------------------------------+
	|	C / M : -- / 2008-10-9
	+----------------------------------+
	*/

	//	[CH]	制定图片背景大小
	$im	=	imagecreatetruecolor( 90, 30 ) or die ( "Cannot Initialize new GD image stream" );
	/*
	+----------------------------------+
	|	设定三种颜色
	+----------------------------------+
	|	C / M : 2008-9-15 / --
	+----------------------------------+
	*/
	$green	=	imagecolorallocate( $im, 154, 197, 42 );
	$white	=	imagecolorallocate( $im, 255, 255, 255 );
	$blue	=	imagecolorallocate( $im, 62, 80, 115 );

	putenv( 'GDFONTPATH=' . realpath( '.' ) );
	$font	=	ROOT_PATH . '/FetteSteinschrift.ttf';
	//print_r( realpath( '.' ) );

	//	[CH]	采用区域填充法，设定（0,0）
	imagefill( $im, 0, 0, $white );

	while( ( $authnum = rand() % 100000 ) < 10000 );

	//	[CH]	将四位整数验证码绘入图片
	$_SESSION['authcode']	=	$authnum;

	@imagettftext( $im, 18, 6, 0, 28, $green, $font, $_SESSION['authcode'] );

	//	[CH]	加入干扰象素
	/*for( $i = 0; $i < 1000; $i++ )
	{
		$randcolor	=	ImageColorallocate( $im, rand( 0, 255 ), rand( 0, 255 ), rand( 0, 255 ) );
		imagesetpixel( $im, rand() % 100 , rand() % 100 , $randcolor );
	}*/

	ImagePNG( $im );
	ImageDestroy( $im );
?>